package com.web;



import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import exception.DAOSystemException;
import model.UserDTO;
import model.CompensationLeaveDTO;
import bizlogic.UserManager;


/* ************************************************************** */
/* Servlet implementation to load data for overtime entry form    */
/* Added by : Suganthi V Subramaniam                              */
/* *************************************************************  */

 public class LoadDataOTServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public LoadDataOTServlet() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}   	  
	private void processRequest(HttpServletRequest request, HttpServletResponse response) {
		UserDTO us =(UserDTO)request.getSession().getAttribute("user");
		String id = us.getId().toString();
		UserManager um = new UserManager();
		UserDTO data=null;
		try {
			data = um.findUser(id);
		} catch (DAOSystemException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		HttpSession ldsession=request.getSession(true);
		ldsession.setAttribute("user", data);
		RequestDispatcher rd = request.getRequestDispatcher("/OverTimeEntryForm.jsp");
		try {
			rd.forward(request, response);
		} catch (ServletException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}